package cn.wolfcode.luowowo.mgrsite.controller;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.Region;
import cn.wolfcode.luowowo.article.query.RegionQuery;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IRgionService;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by LENOVO on 2019/8/9.
 */
@Controller
@RequestMapping("region")
public class RegionController {

    @Reference
    private IRgionService rgionService;
    @Reference
    private IDestinationService destinationService;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") RegionQuery qo){
        PageInfo pageInfo = rgionService.query(qo);
        model.addAttribute("pageInfo",pageInfo);
        return "region/list";
    }
    //查询所有的目的地
    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep){

        return  destinationService.getDestByDeep(deep);
    }
    //关联目的地的查询
    @RequestMapping("/getDestByRegionId")
    @ResponseBody
    public Object getDestByRegionId(Long rid){

        return  destinationService.getDestByRegionId(rid);
    }




    //新增或者添加操作
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Region region){
        rgionService.saveOrUpdate(region);
        return   AjaxResult.SUCCESS;
    }
    //删除操作
    @RequestMapping("/delete")
    @ResponseBody
    public Object saveOrUpdate(Long id){
        rgionService.delete(id);
        return   AjaxResult.SUCCESS;
    }
    //设置为热门的操作
    @RequestMapping("/changeHotValue")
    @ResponseBody
    public Object changeHotValue(int hot,Long id){
        rgionService.changeHotValue(hot,id);
        return   AjaxResult.SUCCESS;
    }
}
